package lesson;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql:///db1?useSSL=false";
        String user = "root";
        String psd = "1234";
        Connection connection = DriverManager.getConnection(url,user,psd);

        String sql1 = "update account set money = 2999 where id = 4";
        String sql2 = "update account set money = 999999 where id = 10";

        Statement st = connection.createStatement();

        try{
            connection.setAutoCommit(false);
            int i = st.executeUpdate(sql1);
            System.out.println(i);
            int i2= 3/0;
            int i1 = st.executeUpdate(sql2);
            System.out.println(i1);
            connection.commit();
        }catch (Exception e){
            connection.rollback();
        }

        st.close();
        connection.close();
    }
}
